<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">



    <title>博客列表</title>
    <link rel="stylesheet" href="css/list.css">
    <link rel="stylesheet" href="css/blog_list.css">
    <link rel="stylesheet" href="css/iconfont.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/urlutils.js"></script>
    <style>
        
        .nav{
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            height: 50px;
            display: flex;
            align-items: center;
        }
        .container{
            padding-top: 80px;
            height: auto;
        }
        .container-right{
            width: auto;
        }
        .blog-pagnation-wrapper{
            height: 40px;
            margin: 16px 0;
            text-align: center;
        }
        .blog-pagnation-item{
            display: inline-block;
            padding: 8px;
            border: 1px solid #d0d0d5;
            color: #333;
        }
        .blog-pagnation-item:hover{
            background: #4e4eeb;
            color: #fff;
        }
        .blog-pagnation-item:active{
            background: #4e4eeb;
            color: #fff;
        }
        .search-txt{
            flex: 1;
            width: 30%;
            height: 35px;
            border: 1px solid #e8e8ed;
            background: #f5f6f7;
            font-size: 14px;
            margin-left: 70%;
            border-radius: 16px 0 0 16px;
            padding: 8px 30px 8px 0;
            outline:none;
        }
        .search-btn{
            float: left;
            width: 80px;
            height: 35px;
            font-size: 14px;
            border-radius: 0 16px 16px 0;
            background-color: #fc5531;
            color: #fff;
            outline:none;
            border: 1px solid #fc5531;
            margin-right: 40px;
        }
        .search-btn:active{
            background: #4e4eeb;
            color: #fff;
        }
    </style>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/log.jpg" alt="">
        <span class="title">我的博客系统</span>
        <!-- 用来占据中间位置 -->
        <div class="spacer">
            <input type="text" class="search-txt" placeholder="想搜啥?" id="search-text"/>
        </div>
           <button class="search-btn" onclick="doSearch()"> <i class="iconfont icon-search"></i>搜索 </button>
        <a href="myblog_list.html">个人主页</a>
        <a href="blog_add.html">写博客</a>
    </div>
    <!-- 版心 -->
    <div class="container">
        <!-- 右侧内容详情 -->
        <div class="container-right" style="width: 100%;">

            <!-- 每一篇博客包含标题, 摘要, 时间 -->
            <div class="blog" id="createDiv">

            </div>
            <hr>
            <div class="blog-pagnation-wrapper">
                <button class="blog-pagnation-item" onclick="doFirst()">首页</button>
                <button class="blog-pagnation-item" onclick="doBefore()">上一页</button>
                当前<span id="pindex"></span> 页/<span id="pszie"></span>页
                <button class="blog-pagnation-item" onclick="doNext()">下一页</button>
                <button class="blog-pagnation-item" onclick="doLast()">末页</button>
            </div>
        </div>
    </div>

        <script>
            var pasize=3;       //每页显示的条数
            var pindex=1;       //当前页面
            var totalpage=1;   //总页数
            function init(){
                pindex=getParamValue("pindex");
                if(pindex==null){
                    pindex=1;
                }
                jQuery("#pindex").html(pindex);
                $.post("articleinfo/index",{
                        "pindex":pindex,
                        "ceo":1,
                        "pasize":pasize
                    },
                    function (res){
                        if(res.code==200 && res.data!=null){
                            var createHtml="";
                            var artlist=res.data.date;
                            totalpage=res.data.num;
                            jQuery("#pszie").html(totalpage);
                            if(artlist==null || artlist.length==0){
                                //没有文章。
                                createHtml+="<h3>未有文章，请期待</h3>";
                            }else{
                                for(var i=0;i<artlist.length;i++){
                                    var art=artlist[i];
                                    createHtml+='<div class="blog">';
                                    createHtml+='<div class="title">'+art.title+'</div>';
                                    createHtml+='<div class="date">';
                                    createHtml+='<span>'+art.createtime+'</span>';
                                    createHtml+='&nbsp;&nbsp;';
                                    createHtml+='<span>'+art.name+'</span>';
                                    createHtml+='</div>';
                                    createHtml+='<div class="desc">'+art.synopsis+'</div>';
                                    createHtml+='<a href=blog_content.html?id='+art.aid+' class="detail" style="margin-top: 10px;margin-left: 80%;margin-bottom: 10px;">查看全文>></a>';
                                    createHtml+='</div>';
                                }
                            }
                            jQuery("#createDiv").html(createHtml);
                        }else{
                            alert("抱歉，操作失败:"+res.msg);
                            window.location.href="login.html";
                        }
                    })
            }init();
            function doFirst(){
                if(pindex<=1){
                    alert("已经在首页了");
                    return false;
                }
                location.href="blog_list2.html";
            }
            function doLast(){
                if(pindex>=totalpage){
                    alert("已经在末页了");
                    return false;
                }
                location.href="blog_list2.html?pindex="+totalpage;
            }
            function doBefore(){
                // 1.判断是否在首页
                if(pindex<=1){
                    alert("已经在首页了，无需跳转！");
                    return false;
                }
                // 2.跳转上一页
                location.href = "blog_list2.html?pindex="+(parseInt(pindex)-1);
            }
            // 点击“写一页”
            function doNext(){
                // 1.判断是否在末页
                if(pindex>=totalpage){
                    alert("已经在末页了，无需跳转！");
                    return false;
                }
                // 2.跳转到下一页
                location.href = "blog_list2.html?pindex="+(parseInt(pindex)+1);
            }
            //搜索
            function doSearch(){
                var text = jQuery("#search-text").val();
                location.href="blog_find.html?text="+text;
            }
        </script>
</body>
</html>